import Vue from 'vue'
import App from './App'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css';
import './assets/style/style.css';
import router from './router';
import axios from "axios";

import api from "./api/manage/index"

// 全局组件注册
import mNavigationBar from "./components/Public/NavigationBar.vue"
import mListModuleTitle from "./components/Public/ListModuleTitle.vue"
import mListItem from "./components/Public/ListItem.vue"
import DraftsList from "./components/Public/DraftsList.vue"
import ReagentList from "./components/Public/ReagentList.vue"
import EditPageTitle from "./components/Public/EditPageTitle.vue"
import EditInputLine from "./components/Public/EditInputLine.vue"
import EditEditor from "./components/Public/EditEditor.vue"
import EditButton from "./components/Public/EditButton.vue"

import wEditor from "./components/Public/Editer.vue"
//全局自定义组件
Vue.component("mNavigationBar", mNavigationBar);
Vue.component("mListModuleTitle", mListModuleTitle);
Vue.component("mListItem", mListItem);
Vue.component("DraftsList", DraftsList);
Vue.component("ReagentList", ReagentList);
Vue.component("EditPageTitle", EditPageTitle);
Vue.component("EditInputLine", EditInputLine);
Vue.component("wEditor", wEditor);
Vue.component("EditEditor", EditEditor);
Vue.component("EditButton", EditButton);
//全局自定义组件
Vue.prototype.$api = api; // 将api挂载到vue的原型上
Vue.prototype.$axios = axios; // 将api挂载到vue的原型上

Vue.config.productionTip = false

Vue.use(ElementUI)

/**
* @description 登录验证逻辑
*/
router.beforeEach((to, from, next) => {
  // 判断是否前往登录页，如果是前往登录页，从本地存储sessionStorage中删除登录信息
  if (to.path == '/login') {
    sessionStorage.removeItem('user');
  }
  let user = JSON.parse(sessionStorage.getItem('user'));
  if (!user && to.path != '/login') {
    next({ path: '/login' })
  } else {
    next()
  }
})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  render: h => h(App)
})
